//
//  POIModelDataSourceProtocolTests.swift
//  travelMapMvvm-swift2
//
//  Created by green on 15/11/4.
//  Copyright © 2015年 travelMapMvvm-swift2. All rights reserved.
//

import Foundation
import XCTest
import ReactiveCocoa
import TMDatasourceLib
import TMCommonLib

class POIModelDataSourceProtocolTests: XCTestCase {
    
    var poiModelDataSourceProtocol: POIModelDataSourceProtocol!
    
    override func setUp() {
        super.setUp()
        
        poiModelDataSourceProtocol = POIModelDataSource.shareInstance()
    }
    
    override func tearDown() {
        super.tearDown()
    }
    
    /**
     查询攻略POI测试
     */
    func testQueryPOIListByStrategyId() {
        
        let expectation = expectationWithDescription(kURL+"getArticlePOIs")
        
        poiModelDataSourceProtocol.queryPOIListByStrategyId(nil, strategyId: "3328778").subscribeNext({ (any:AnyObject!) -> Void in
            
            expectation.fulfill()
            XCTAssert(any is [POIModel],"response obj is not [POIModel]")
            
            print(any as! [POIModel])
            
        }, error: { (error:NSError!) -> Void in
            
            expectation.fulfill()
            XCTFail(error.localizedDescription)
            
        })
        
        waitForExpectationsWithTimeout(10, handler: {error in
        })
    }
    
    /**
     查询城市POI测试
     */
    func testQueryPOIListByCityId() {
        
        let expectation = expectationWithDescription(kURL+"getDestinationPOIs")
        
        poiModelDataSourceProtocol.queryPOIListByCityId(1, pageSize: 10, poiTypeCodes: nil, cityId: "10579").subscribeNext({ (any:AnyObject!) -> Void in
            
            expectation.fulfill()
            XCTAssert(any is [POIModel],"response obj is not [POIModel]")
            
            print(any as! [POIModel])
            
        }, error: { (error:NSError!) -> Void in
            
            expectation.fulfill()
            XCTFail(error.localizedDescription)
            
        })
        
        waitForExpectationsWithTimeout(10, handler: {error in
        })
        
    }
    
    /**
     查询关键字POI测试
     */
    func testQueryPOIListByKeyword() {
        
        let expectation = expectationWithDescription(kURL+"getPOIByKeyword")
        
        poiModelDataSourceProtocol.queryPOIListByKeyword(1, pageSize: 10, poiTypeCodes: nil, keyword: "博物馆").subscribeNext({ (any:AnyObject!) -> Void in
            
            expectation.fulfill()
            XCTAssert(any is [POIModel],"response obj is not [POIModel]")
            
            print(any as! [POIModel])
            
        }, error: { (error:NSError!) -> Void in
            
            expectation.fulfill()
            XCTFail(error.localizedDescription)
            
        })
        
        waitForExpectationsWithTimeout(10, handler: {error in
        })
        
    }
    
    /**
     查询已收藏的POI测试
     */
    func testQueryPOIListByUserId() {
        
        let expectation = expectationWithDescription(kURL+"favoritePOI")
        
        poiModelDataSourceProtocol.queryPOIListByUserId(1, pageSize: 10, poiTypeCodes: [], userId: "4610549").subscribeNext({ (any:AnyObject!) -> Void in
            
            expectation.fulfill()
            XCTAssert(any is [POIModel],"response obj is not [POIModel]")
            
            print(any as! [POIModel])
            
        }, error: { (error:NSError!) -> Void in
            
            expectation.fulfill()
            XCTFail(error.localizedDescription)
            
        })
        
        waitForExpectationsWithTimeout(10, handler: {error in
        })
        
    }
    
    /**
     查询指定目的地周边POI测试
     */
    func testQueryPOIListByCenterPOIId() {
        
        let expectation = expectationWithDescription(kURL+"getAroundPoi")
        
        poiModelDataSourceProtocol.queryPOIListByCenterPOIId(1, pageSize: 10, poiTypeCodes: [], centerPoiId: "1255328437",poiType:1).subscribeNext({ (any:AnyObject!) -> Void in
            
            expectation.fulfill()
            XCTAssert(any is [POIModel],"response obj is not [POIModel]")
            
            print(any as! [POIModel])
            
        }, error: { (error:NSError!) -> Void in
            
            expectation.fulfill()
            XCTFail(error.localizedDescription)
            
        })
        
        waitForExpectationsWithTimeout(10, handler: {error in
        })
        
    }
    
    /**
     收藏/取消目的地测试
     */
    func testCollectPOI() {
        
        let expectation = expectationWithDescription(kURL + "collectPOI")
        
        poiModelDataSourceProtocol.collectPOI("472622130", userId: 4610549, isFavorite: true, poiType: 1).subscribeNext({ (any:AnyObject!) -> Void in
            
            expectation.fulfill()
            XCTAssert(any is String, "response obj is not string type")
            
            let msg = any as? String
            
            print(msg)
            
        }) { (error:NSError!) -> Void in
            
            expectation.fulfill()
            XCTAssert(error.localizedDescription != DataError.CollectPOIError(nil).error.localizedDescription, "collectPOI failure")
        }
        
        waitForExpectationsWithTimeout(10, handler: {error in
        })
    }
    
    /**
     去过/取消去过目的地测试
     */
    func testDidVisitPOI() {
        
        let expectation = expectationWithDescription(kURL + "setTraveledPoi")
        
        poiModelDataSourceProtocol.didVisitPOI("472622130", userId: 4610549, isTraveled: true, poiType: 1).subscribeNext({ (any:AnyObject!) -> Void in
            
            expectation.fulfill()
            XCTAssert(any is String, "response obj is not string type")
            
            let msg = any as? String
            
            print(msg)
            
        }) { (error:NSError!) -> Void in
            
            expectation.fulfill()
            XCTAssert(error.localizedDescription != DataError.DidVisitPOIError(nil).error.localizedDescription, "didVisitPOI failure")
        }
        
        waitForExpectationsWithTimeout(10, handler: {error in
        })
    }
}